﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockPrjTeam2.Biz;
using MockPrjTeam2.Entity;

namespace MockPrjTeam2.Pages.Views
{
    public partial class ListGovOfficeRegion : System.Web.UI.Page
    {
        GovOfficeRegionBiz _govOfficeRegionBiz = new GovOfficeRegionBiz();
        private static int _flag;
        private static int _check;
        private static string _key = string.Empty;
        private GovOfficeRegionBiz govOfficeRegionBiz =new GovOfficeRegionBiz();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _flag = 0;
                _check = 0;
                LoadAllGovOfficeRegion();
            }
        }


        private void LoadAllGovOfficeRegion()
        {
            grvGovOfficeRegion.DataSource = _govOfficeRegionBiz.GetAll();
            grvGovOfficeRegion.DataBind();
        }



        protected void StartWithByNames(object sender, CommandEventArgs e)
        {
            if (CheckBoxInActive.Checked)
            {
                _check = 1;
                _flag = 1;
                _key = e.CommandName;
                grvGovOfficeRegion.DataSource = govOfficeRegionBiz.StartWithByNames(_key, _flag);
                grvGovOfficeRegion.DataBind();
            }
            else
            {
                _check = 1;
                _flag = 0;
                _key = e.CommandName;
                grvGovOfficeRegion.DataSource = govOfficeRegionBiz.StartWithByNames(_key, _flag);
                grvGovOfficeRegion.DataBind();
            }
        }


        protected void LinkButtonGovtOfficeRegion_Command(object sender, CommandEventArgs e)
        {
            Response.Redirect(string.Format(CultureInfo.CurrentCulture, "../Forms/GovOfficeRegionDetails.aspx?id={0}", e.CommandName));
        }


        
        protected void CheckBoxInactiveCheckedChanged(object sender, EventArgs e)
        {
            if (_check == 1)
            {
                if (CheckBoxInActive.Checked && _check == 1)
                {
                    _flag = 1;
                    grvGovOfficeRegion.DataSource = govOfficeRegionBiz.StartWithByNames(_key, _flag);
                    grvGovOfficeRegion.DataBind();
                }
                else if (CheckBoxInActive.Checked == false && _check == 1)
                {
                    _flag = 0;
                    grvGovOfficeRegion.DataSource = govOfficeRegionBiz.StartWithByNames(_key, _flag);
                    grvGovOfficeRegion.DataBind();

                }

            }
            else if (_check == 0)
            {
                if (CheckBoxInActive.Checked && _check == 0)
                {
                    grvGovOfficeRegion.DataSource = govOfficeRegionBiz.GetActive();
                    grvGovOfficeRegion.DataBind();
                }
                else
                {
                    _flag = 0;
                    LoadAllGovOfficeRegion();
                }
            }
        }
        

       protected void LbtnGovOfficeRegionName_Command(Object sender,CommandEventArgs e)
       {
           
           Response.Redirect(string.Format(CultureInfo.CurrentCulture, "GovOfficeRegionDetails.aspx?id={0}", e.CommandName));
       }



       protected void grvGovOfficeRegion_PageIndexChanging(object sender, GridViewPageEventArgs e)
       {
           grvGovOfficeRegion.PageIndex = e.NewPageIndex;
            if (_check == 1)
            {
                if (CheckBoxInActive.Checked && _check == 1)
                {
                    _flag = 1;
                    grvGovOfficeRegion.DataSource = govOfficeRegionBiz.StartWithByNames(_key, _flag);
                }
                else if (CheckBoxInActive.Checked == false && _check == 1)
                {
                    _flag = 0;
                    grvGovOfficeRegion.DataSource = govOfficeRegionBiz.StartWithByNames(_key, _flag);

                }
            }
            else if (_check == 0)
            {
                if (CheckBoxInActive.Checked && _check == 0)
                {
                    grvGovOfficeRegion.DataSource = govOfficeRegionBiz.GetActive();
                }
                else
                {
                    _flag = 0;
                    grvGovOfficeRegion.DataSource = govOfficeRegionBiz.GetAll();
                }
            }
            grvGovOfficeRegion.DataBind();
       }

    }
}